# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
package(
    default_visibility = ["//visibility:public"],
    licenses = ["notice"],
)

cc_library(
    name = "app_db_acl_def_table_manager",
    srcs = ["app_db_acl_def_table_manager.cc"],
    hdrs = ["app_db_acl_def_table_manager.h"],
    deps = [
        ":redis_connections",
        "//gutil:status",
        "//p4_pdpi:ir_cc_proto",
        "//p4_pdpi/utils:annotation_parser",
        "//p4rt_app/utils:table_utility",
        "@com_github_google_glog//:glog",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/types:optional",
        "@sonic_swss_common//:libswsscommon",
    ],
)

cc_test(
    name = "app_db_acl_def_table_manager_test",
    srcs = ["app_db_acl_def_table_manager_test.cc"],
    deps = [
        ":app_db_acl_def_table_manager",
        ":redis_connections",
        "//gutil:status_matchers",
        "//p4rt_app/sonic/adapters:fake_producer_state_table_adapter",
        "//p4rt_app/sonic/adapters:fake_sonic_db_table",
        "//p4rt_app/utils:ir_builder",
        "@com_github_google_glog//:glog",
        "@com_google_absl//absl/strings",
        "@com_google_googletest//:gtest_main",
        "@com_google_protobuf//:protobuf",
        "@sonic_swss_common//:libswsscommon",
    ],
)

cc_library(
    name = "app_db_manager",
    srcs = ["app_db_manager.cc"],
    hdrs = ["app_db_manager.h"],
    deps = [
        ":app_db_to_pdpi_ir_translator",
        ":redis_connections",
        ":response_handler",
        "//gutil:collections",
        "//gutil:status",
        "//p4_pdpi:ir_cc_proto",
        "//p4rt_app/utils:status_utility",
        "//p4rt_app/utils:table_utility",
        "@com_github_google_glog//:glog",
        "@com_google_absl//absl/container:btree",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@sonic_swss_common//:libswsscommon",
    ],
)

cc_test(
    name = "app_db_manager_test",
    srcs = ["app_db_manager_test.cc"],
    deps = [
        ":app_db_manager",
        ":redis_connections",
        "//gutil:proto_matchers",
        "//gutil:status_matchers",
        "//p4_pdpi:ir",
        "//p4_pdpi:ir_cc_proto",
        "//p4rt_app/sonic/adapters:mock_consumer_notifier_adapter",
        "//p4rt_app/sonic/adapters:mock_producer_state_table_adapter",
        "//p4rt_app/sonic/adapters:mock_table_adapter",
        "//p4rt_app/tests/lib:app_db_entry_builder",
        "//p4rt_app/utils:table_utility",
        "//sai_p4/instantiations/google:sai_p4info_cc",
        "@com_github_google_glog//:glog",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/memory",
        "@com_google_absl//absl/status:statusor",
        "@com_google_googleapis//google/rpc:code_cc_proto",
        "@com_google_googletest//:gtest_main",
        "@com_google_protobuf//:protobuf",
    ],
)

cc_library(
    name = "app_db_to_pdpi_ir_translator",
    srcs = ["app_db_to_pdpi_ir_translator.cc"],
    hdrs = ["app_db_to_pdpi_ir_translator.h"],
    deps = [
        "//gutil:collections",
        "//gutil:status",
        "//p4_pdpi:ir_cc_proto",
        "//p4_pdpi/utils:ir",
        "//p4rt_app/utils:table_utility",
        "@com_github_google_glog//:glog",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@sonic_swss_common//:libswsscommon",
    ],
)

cc_test(
    name = "app_db_to_pdpi_ir_translator_test",
    srcs = ["app_db_to_pdpi_ir_translator_test.cc"],
    deps = [
        ":app_db_to_pdpi_ir_translator",
        "//gutil:proto_matchers",
        "//gutil:status_matchers",
        "//p4_pdpi:ir",
        "//sai_p4/instantiations/google:sai_p4info_cc",
        "@com_github_google_glog//:glog",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_googletest//:gtest_main",
        "@com_google_protobuf//:protobuf",
    ],
)

cc_library(
    name = "receive_genetlink",
    srcs = ["receive_genetlink.cc"],
    hdrs = ["receive_genetlink.h"],
    copts = [
        "-I",
        "/usr/include/libnl3/",
    ],  # Sonic-dependancy
    linkopts = [
        "-lnl-3",
        "-lnl-genl-3",
        "-lnl-nf-3",
        "-lnl-route-3",
    ],
    # copts = ["-I /usr/include/libnl3/"],
    deps = [
        "//gutil:status",
        "@com_github_google_glog//:glog",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
    ],
)

cc_library(
    name = "packetio_interface",
    hdrs = ["packetio_interface.h"],
    deps = [
        ":receive_genetlink",
        "@com_google_absl//absl/status",
    ],
)

cc_library(
    name = "packetio_selectables",
    srcs = ["packetio_selectables.cc"],
    hdrs = ["packetio_selectables.h"],
    deps = [
        ":receive_genetlink",
        "@com_github_google_glog//:glog",
        "@sonic_swss_common//:libswsscommon",
    ],
)

cc_library(
    name = "packetio_port",
    srcs = ["packetio_port.cc"],
    hdrs = ["packetio_port.h"],
    deps = [
        ":packetio_selectables",
        ":receive_genetlink",
        "//gutil:collections",
        "//gutil:status",
        "//p4_pdpi/utils:ir",
        "//p4rt_app/sonic/adapters:system_call_adapter",
        "@com_github_google_glog//:glog",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/memory",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@sonic_swss_common//:libswsscommon",
    ],
)

cc_library(
    name = "packetio_impl",
    srcs = ["packetio_impl.cc"],
    hdrs = ["packetio_impl.h"],
    deps = [
        ":packetio_interface",
        ":packetio_port",
        ":receive_genetlink",
        "//gutil:collections",
        "//gutil:status",
        "//p4rt_app/sonic/adapters:system_call_adapter",
        "@com_github_google_glog//:glog",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@sonic_swss_common//:libswsscommon",
    ],
)

cc_test(
    name = "packetio_impl_test",
    srcs = ["packetio_impl_test.cc"],
    deps = [
        ":packetio_impl",
        "//gutil:status_matchers",
        "//p4rt_app/sonic/adapters:mock_system_call_adapter",
        "@com_google_absl//absl/cleanup",
        "@com_google_absl//absl/memory",
        "@com_google_absl//absl/status",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_library(
    name = "fake_packetio_interface",
    srcs = ["fake_packetio_interface.cc"],
    hdrs = ["fake_packetio_interface.h"],
    deps = [
        ":packetio_interface",
        "//gutil:collections",
        "@com_github_google_glog//:glog",
        "@com_google_absl//absl/base:core_headers",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/synchronization",
    ],
)

cc_test(
    name = "packetio_port_test",
    srcs = ["packetio_port_test.cc"],
    deps = [
        ":packetio_port",
        "//gutil:status_matchers",
        "//p4rt_app/sonic/adapters:mock_system_call_adapter",
        "@com_github_google_glog//:glog",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_library(
    name = "redis_connections",
    hdrs = ["redis_connections.h"],
    deps = [
        "//p4rt_app/sonic/adapters:consumer_notifier_adapter",
        "//p4rt_app/sonic/adapters:producer_state_table_adapter",
        "//p4rt_app/sonic/adapters:table_adapter",
    ],
)

cc_library(
    name = "response_handler",
    srcs = ["response_handler.cc"],
    hdrs = ["response_handler.h"],
    deps = [
        "//gutil:collections",
        "//gutil:status",
        "//p4_pdpi:ir_cc_proto",
        "//p4_pdpi/utils:ir",
        "//p4rt_app/sonic/adapters:consumer_notifier_adapter",
        "//p4rt_app/sonic/adapters:table_adapter",
        "//p4rt_app/utils:event_execution_time_monitor",
        "@com_github_google_glog//:glog",
        "@com_google_absl//absl/container:btree",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/time",
        "@com_google_googleapis//google/rpc:code_cc_proto",
        "@sonic_swss_common//:libswsscommon",
    ],
)

cc_test(
    name = "response_handler_test",
    srcs = ["response_handler_test.cc"],
    deps = [
        ":response_handler",
        "//gutil:proto_matchers",
        "//gutil:status_matchers",
        "//p4_pdpi:ir",
        "//p4_pdpi:ir_cc_proto",
        "//p4rt_app/sonic/adapters:mock_consumer_notifier_adapter",
        "//p4rt_app/sonic/adapters:mock_table_adapter",
        "@com_github_google_glog//:glog",
        "@com_google_absl//absl/status",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_library(
    name = "state_verification",
    srcs = ["state_verification.cc"],
    hdrs = ["state_verification.h"],
    deps = [
        "//gutil:status",
        "//p4rt_app/sonic/adapters:table_adapter",
        "@com_github_google_glog//:glog",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
    ],
)

cc_test(
    name = "state_verification_test",
    srcs = ["state_verification_test.cc"],
    deps = [
        ":state_verification",
        "//gutil:status_matchers",
        "//p4rt_app/sonic/adapters:mock_table_adapter",
        "@com_google_absl//absl/status",
        "@com_google_googletest//:gtest_main",
    ],
)
